package com.cy.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.cy.bean.Show;
import com.cy.util.ConnectionFactory;

public class MainDaoImpl implements MainDao {
	public List<Show> show() {
		Connection conn = ConnectionFactory.getConnection();
		PreparedStatement psmt = null;
		ResultSet rs = null;
		try {
			String sql = "select count(game_id) as total ,game_name from sell_info,games where game_id=games.id group by game_id order by total desc limit 10";
			psmt = conn.prepareStatement(sql);
			rs = psmt.executeQuery();
			List<Show> showvalue = new ArrayList<Show>();
			while (rs.next()) {
				showvalue.add(new Show(rs.getString("game_name"), rs.getInt("total")));
			}
			return showvalue;
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			ConnectionFactory.close(conn, psmt, rs);
		}
		return null;
	}
}